package com.example.fashionshoes.controller.admin;

import com.example.fashionshoes.pojo.dto.UserInfoDTO;
import com.example.fashionshoes.pojo.po.Result;
import com.example.fashionshoes.pojo.po.User;
import com.example.fashionshoes.pojo.vo.UserVo;
import com.example.fashionshoes.service.UserService;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController("adminUserController")
@RequestMapping("/admin")
public class UserController {
    @Resource
    private UserService userService;

    /**
     * 禁用启用用户账户
     * @param userInfoDTO 用户id,status
     * @return 操作的结果
     */
    @PostMapping("/status")
    public Result<Boolean> modifyUserStatus(@Validated @RequestBody UserInfoDTO userInfoDTO){
        boolean  isTrue= userService.modifyUserStatus(userInfoDTO);
        return Result.success(isTrue);
    }

    /**
     * 获取除管理员以外的用户信息
     * @return 除管理员以外的用户信息
     */
    @GetMapping("/info")
    public Result<List<UserVo>> getUserInfo(){
        List<UserVo> userVoList = userService.getUser();
        return Result.success(userVoList);
    }

    /**
     * 根据id获取用户信息
     * @param id 用户id
     * @return 用户信息
     */
    @GetMapping
    public Result<User> getUserById(Integer id){
        User user = userService.getById(id);
        user.setPassword(null);
        return Result.success(user);
    }
}
